#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MOD=1e9+7;
int k,buc[6],f[16][16][16][16][16][16];
bool vis[16][16][16][16][16][16];
int dfs(int a,int b,int c,int d,int e,int last)
{
	if(vis[a][b][c][d][e][last])return f[a][b][c][d][e][last];
	if(!(a+b+c+d+e))return 1;
	int t=0;
	if(a)t=(t+(LL)(a-(last==2))*dfs(a-1,b,c,d,e,1)%MOD)%MOD;
	if(b)t=(t+(LL)(b-(last==3))*dfs(a+1,b-1,c,d,e,2)%MOD)%MOD;
	if(c)t=(t+(LL)(c-(last==4))*dfs(a,b+1,c-1,d,e,3)%MOD)%MOD;
	if(d)t=(t+(LL)(d-(last==5))*dfs(a,b,c+1,d-1,e,4)%MOD)%MOD;
	if(e)t=(t+(LL)e*dfs(a,b,c,d+1,e-1,5)%MOD)%MOD;
	f[a][b][c][d][e][last]=t;
	vis[a][b][c][d][e][last]=true;
	return f[a][b][c][d][e][last];
}
int main()
{
	scanf("%d",&k);
	for(int i=1;i<=k;++i)
	{
		int x;
		scanf("%d",&x);
		++buc[x];
	}
	printf("%d\n",dfs(buc[1],buc[2],buc[3],buc[4],buc[5],0));
	return 0;
}
